#include "Graphics/PiccoloVKQueue.h"

namespace Piccolo
{
    PiccoloVKQueue::PiccoloVKQueue(uint32_t familyIndex, uint32_t index, VkQueue queue, bool bPresent)
        : mFamilyIndex(familyIndex), mIndex(index), mQueue(queue), mPresent(bPresent)
    {
        LOG_T("Create a new queue: {0} - {1} - {2}, present: {3}", mFamilyIndex, index, (void*)queue, bPresent);
    }

    void PiccoloVKQueue::Submit(const std::vector<VkCommandBuffer> &commandBuffers, const std::vector<VkSemaphore>& waitSemaphores, const std::vector<VkSemaphore>& signalSemaphores, VkFence frameFence)
    {
        VkPipelineStageFlags waitDstStageMask[] = { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT };
        VkSubmitInfo submitInfo =
        {
            .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
            .pNext = nullptr,
            .waitSemaphoreCount = static_cast<uint32_t>(waitSemaphores.size()),
            .pWaitSemaphores = waitSemaphores.data(),
            .pWaitDstStageMask = waitDstStageMask,
            .commandBufferCount = static_cast<uint32_t>(commandBuffers.size()),
            .pCommandBuffers = commandBuffers.data(),
            .signalSemaphoreCount = static_cast<uint32_t>(signalSemaphores.size()),
            .pSignalSemaphores = signalSemaphores.data()
        };
        CALL_VK(vkQueueSubmit(mQueue, 1, &submitInfo, frameFence));
    }

    void PiccoloVKQueue::WaitIdle() const
    {
        CALL_VK(vkQueueWaitIdle(mQueue));
    }
}
